package com.pair.micro.fee.modules.charge.controller;


import com.pair.micro.common.operatelog.annotations.OperateLog;
import com.pair.micro.common.operatelog.enums.OperateTypeEnum;
import com.pair.micro.common.response.MicroResult;
import com.pair.micro.common.utils.PageResult;
import com.pair.micro.fee.modules.charge.convert.ChargeProjectConvert;
import com.pair.micro.fee.modules.charge.convert.ChargeReceiveConvert;
import com.pair.micro.fee.modules.charge.entity.ChargeProjectEntity;
import com.pair.micro.fee.modules.charge.entity.ChargeReceiveEntity;
import com.pair.micro.fee.modules.charge.entity.RoomOwnerEntity;
import com.pair.micro.fee.modules.charge.query.ChargeProjectQuery;
import com.pair.micro.fee.modules.charge.query.ChargeReceiveQuery;
import com.pair.micro.fee.modules.charge.service.ChargeProjectService;
import com.pair.micro.fee.modules.charge.service.ChargeReceiveService;
import com.pair.micro.fee.modules.charge.vo.ChargeProjectVO;
import com.pair.micro.fee.modules.charge.vo.ChargeReceiveVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@RestController
@RequestMapping("fx/receive")
@Tag(name = "收取账单")
@AllArgsConstructor
public class ChargeReceiveController {

    private final ChargeReceiveService chargeReceiveService;
    @GetMapping("page")
    @Operation(summary = "分页查询")
    @PreAuthorize("hasAuthority('fee:receive:list')")
    public MicroResult<PageResult<ChargeReceiveVO>> page(@ParameterObject @Valid ChargeReceiveQuery chargeReceiveQuery){
        PageResult<ChargeReceiveVO> page = chargeReceiveService.page(chargeReceiveQuery);
        return MicroResult.ok(page);
    }

    @PostMapping
    @Operation(summary = "保存")
    @OperateLog(type = OperateTypeEnum.INSERT)
//  @PreAuthorize("hasAuthority('fee:receive:save')")
    public MicroResult<String> save(@RequestBody @Valid ChargeReceiveVO vo) {

        List<ChargeProjectEntity> list = chargeReceiveService.checkParams(vo);

        chargeReceiveService.save(list,vo);

        return MicroResult.ok();
    }


    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('fee:receive:info')")
    public MicroResult<ChargeReceiveVO> get(@PathVariable("id") String id) {
        ChargeReceiveEntity entity = chargeReceiveService.getById(id);
        return MicroResult.ok( ChargeReceiveConvert.INSTANCE.convert(entity));
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @OperateLog(type = OperateTypeEnum.DELETE)
    @PreAuthorize("hasAuthority('fee:receive:delete')")
    public MicroResult<String> delete(@RequestBody List<Long> idList) {
        chargeReceiveService.delete(idList);
        return MicroResult.ok();
    }

}
